<!--  -->
<template>
  <div>
    <header-top :fixed="true">
      <template #middle>搜索</template>
    </header-top>

    <!-- 内容 -->
    <div class="container">
      <div class="top-search-bar">
        <search @clickButton="btn" :result_list="result" v-model="val" />
      </div>
    </div>

    <div class="content">
      <h6 style="">搜索内容</h6>
      <div class="searchResult">
        <div v-for="(item, i) in searchResult" :key="i">
          <div @click="goShop(item.id, item.name)">
            <p>品牌店铺</p>
            <span>{{ item.name }}</span>
          </div>
          <div>{{ item.distance }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Search from "../../components/Search/Search.vue";
import HeaderTop from "../../components/headerTop/HeaderTop.vue";
import { reqShops } from "../../apis/profile/profile";
export default {
  data() {
    return {
      val: "",
      result: [],
      searchResult: [],
    };
  },
  components: { HeaderTop, Search },

  methods: {
    btn() {
      if (this.val) {
        this.getData();
      }
    },
    getData() {
      reqShops().then((response) => {
        if (this.searchResult.length > 0) this.searchResult = [];

        response.data.data.forEach((item) => {
          let restr = `[${this.val}]`;
          let re = new RegExp(restr, "gi");
          if (re.test(item.name)) {
            this.searchResult.push(item);
          }
        });
      });
    },
    goShop(id, name) {
      this.$router.push(`/shopBusiness/${id}/${name}`);
    },
  },
  mounted() {},
};
</script>
<style lang="stylus" rel="stylesheet/stylus" scoped>
.content
  h6
    margin: 18px 0 0 10px;
    font-size: 18px
  >div
    font-size:15px;
    margin: 0 0 0 15px;
    padding:10px 0;
.searchResult
  > div
    display: flex;
    align-items: center;
    justify-content: space-between;
    > div
      padding: 10px 0;
      border-bottom: 1px solid #eee;
      > p
        margin:0;
        display: inline-block;
        padding: 0 0.08rem;
        line-height: 0.6rem;
        color: #333;
        background-color: #ffd930 !important;
        font-weight: 900;
        margin-right: 20px;
</style>
